package com.hengtiansoft.lfy.utils;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.hengtiansoft.lfy.LFYApplication;
import com.hengtiansoft.lfy.R;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.shareboard.SnsPlatform;
import com.umeng.socialize.utils.ShareBoardlistener;

/**
 * Created by daiye on 2016/10/26 0026.
 */

public class SharedUtil {
    //分享
    public  static void shared(final Activity actvity, final String sharedtitle, final String sharedbody, final String sharedUrl){
        try {
            //二维码生成
            final Bitmap qrCodeBitmap = BitmapFactory.decodeResource(LFYApplication.getContext().getResources(), R.drawable.logo);
            //final Bitmap qrCodeBitmap = EncodingHandler.createQRCode(sharedUrl, 600);
            //final Bitmap qrCodeBitmap = EncodingHandler.gerateLogoCode(actvity, sharedbody, 600);
            final UMImage image = new UMImage(LFYApplication.getContext(), qrCodeBitmap);

            final SHARE_MEDIA[] displaylist = new SHARE_MEDIA[]
                    {
                            SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.SINA,
                            SHARE_MEDIA.QQ, SHARE_MEDIA.SMS
                    };
            new ShareAction(actvity).setDisplayList(displaylist)
                    .setShareboardclickCallback(new ShareBoardlistener() {
                        @Override
                        public void onclick(SnsPlatform snsPlatform, SHARE_MEDIA share_media) {
                            if (share_media == SHARE_MEDIA.SMS) {
                                new ShareAction(actvity).setPlatform(share_media)
                                        .withText(sharedbody)
                                        .share();
                            } else if (share_media == SHARE_MEDIA.WEIXIN_CIRCLE) {
                                new ShareAction(actvity).setPlatform(share_media)
                                        .withText(sharedbody)
                                        .withTitle(sharedtitle)
                                        .withTargetUrl(sharedUrl)
                                        .withMedia(image)
                                        .share();
                            }  else if (share_media == SHARE_MEDIA.WEIXIN) {
                                new ShareAction(actvity).setPlatform(share_media)
                                        .withText(sharedbody)
                                        .withTitle(sharedtitle)
                                        .withTargetUrl(sharedUrl)
                                        .withMedia(image)
                                        .share();
                            }else if (share_media == SHARE_MEDIA.SINA) {
                                new ShareAction(actvity).setPlatform(share_media)
                                        .withText(sharedbody)
                                        //.withMedia(image)
                                        .share();
                            }else if (share_media == SHARE_MEDIA.QQ) {
                                new ShareAction(actvity).setPlatform(share_media)
                                        .withText(sharedbody)
                                        .withTitle(sharedtitle)
                                        .withTargetUrl(sharedUrl)
                                        .withMedia(image)
                                        .share();
                            }else {
                                new ShareAction(actvity).setPlatform(share_media)
                                        .withText(sharedbody)
                                        .withTitle(sharedtitle)
                                        .withTargetUrl(sharedUrl)
                                        //.withMedia(image)
                                        .share();
                            }
                        }
                    })
                    .open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
